package com.sx.micowell.framework.tools;

import android.text.Selection;
import android.text.Spannable;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.widget.EditText;

/**
 * @author: YY
 * @time: 2021/6/8
 * @describe TODO
 */
public class EditUtils {
    /**
     * 密码显示、隐藏
     * @param isChecked
     * @param editText
     */
    public static void showHide(boolean isChecked, EditText editText) {
        if (isChecked) {
            editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
        } else {
            editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        }
        // 光标置于末尾
        CharSequence charSequence = editText.getText();
        if (charSequence != null) {
            Spannable spannable = (Spannable) charSequence;
            Selection.setSelection(spannable, charSequence.length());
        }
    }
}
